<template>
  <div class="demo">
    <input type="text" v-color="'red'">
    <h3 v-color="'blue'">
      个页面传递的id-----{{ id }}
    </h3>
    {{
      num | filter1
    }}

    <br>
    <el-button @click="getImg">获取头像图片</el-button>
    <wxjButton @click="getGlobMethods('123')">全局方法</wxjButton>
    <div>
      <router-link to="/home">go_home</router-link>
    </div>

    <img :src="imgurl" alt="" />
  </div>
</template>

<script>
export default {

  data() {
    return {
      imgurl:"",
      num:"base_data--"
    };
  },
  // 这个主要用于校验参数
  // 返回false 就会返回 layout 下的error页面
  // 必须要有返回的bool值
  validate({ params }) {
    // console.log("validata", params.id, params);
    if (!params.id) {
      console.log("没有");
      return false;
    }

    return true;
  },
  asyncData({
    params,
  }) {
    // console.log(params);
    return {
      id: params.id || "0000",
    };
  },
  beforeRouteLeave(to, from, next) {
    console.log(to, from);
    next();
  },
  methods: {
    getGlobMethods(id){
      console.log(id)
      this.$show()
    },
    async getImg() {
      let data = await this.$axios.get("/api/randomImg", {
        params: {
          type: "randomimg",
        },
      });

      this.imgurl=data
    },
  },
  components: {},
};
</script>

<style lang='less' scoped>
</style>
